FROM php:8.3.1-fpm-alpine3.19

# 设置 PHPIZE_DEPS
ENV PHPIZE_DEPS="autoconf gcc make"

# 添加阿里云镜像源并安装基础依赖
RUN sed -i '1i https://mirrors.aliyun.com/alpine/v3.19/main' /etc/apk/repositories \
    && sed -i '1i https://mirrors.aliyun.com/alpine/v3.19/community' /etc/apk/repositories \
    && apk update \
    && apk upgrade \
    && apk add --no-cache tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 安装扩展和依赖
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
    && apk --no-cache add \
    dcron \
    curl \
    libzip-dev \
    unzip \
    libpng-dev \
    libjpeg-turbo-dev \
    freetype-dev \
    oniguruma-dev \
    zlib-dev \
    libc-dev \
    nginx \
    && pecl update-channels \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd pdo_mysql zip mbstring exif pcntl bcmath opcache \
    && pecl install igbinary msgpack redis apcu xlswriter --configure-options="--enable-reader" \
    && docker-php-ext-enable igbinary msgpack redis apcu xlswriter opcache \
    && apk del .build-deps \
    && rm -rf /var/cache/apk/*

# 复制配置文件
COPY php.ini /usr/local/etc/php/php.ini
COPY php-fpm.conf /usr/local/etc/php-fpm.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx_fastcgi_params /etc/nginx/nginx_fastcgi_params
COPY nginx_mime_types /etc/nginx/nginx_mime_types
COPY crontab /etc/cron.d/my-cron
RUN chmod 0644 /etc/cron.d/my-cron \
    && crontab /etc/cron.d/my-cron

WORKDIR /var/www/html

EXPOSE 80

ENV COMPOSER_HOME=/composer

ENTRYPOINT ["sh", "docker/service.sh"]

CMD ["sh", "-c", "php-fpm -D && nginx -g 'daemon off;'"]